export function stringify (params) {
  if (!params) {
    return ''
  }
  if (typeof params === 'string') {
    return params
  }
  return Object.keys(params).map(key => `${key}=${params[key]}`).join('&')
}

export function absUrl (url) {
  if (!url || url[0] === '/' || url[0] === '.' || url.includes('://')) {
    return url
  }
  return '/' + url
}

export function joinUrl (url, params) {
  url = absUrl(url)
  params = stringify(params)
  if (!url.includes('?')) {
    params = '?' + params
  } else {
    params = '&' + params
  }
  return url + params
}